package com.handydata.antifraud.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

import com.handydata.antifraud.common.exception.PhoneHaoduanBasedataExCode;
import com.handydata.antifraud.bo.phonehaoduanbasedata.PhoneHaoduanBasedataReqBO;
import com.handydata.antifraud.bo.phonehaoduanbasedata.PhoneHaoduanBasedataResBO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.CreatePhoneHaoduanBasedataReqVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.CreatePhoneHaoduanBasedataResVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.DeletePhoneHaoduanBasedataReqVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.DeletePhoneHaoduanBasedataResVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.ModifyPhoneHaoduanBasedataReqVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.ModifyPhoneHaoduanBasedataResVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.PhoneHaoduanBasedataBeanVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.QueryPhoneHaoduanBasedataReqVO;
import com.handydata.antifraud.vo.phonehaoduanbasedata.QueryPhoneHaoduanBasedataResVO;
import com.handydata.antifraud.service.PhoneHaoduanBasedataService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/phonehaoduanbasedata")
@RestController
public class PhoneHaoduanBasedataController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(PhoneHaoduanBasedataController.class);
	
	@Autowired
	private PhoneHaoduanBasedataService phoneHaoduanBasedataService;
	
	@ApiOperation(value="新增电话号码段", notes="新增电话号码段")
	@ApiImplicitParam(name = "req", value = "新增电话号码段请求对象", required = true, dataType = "CreatePhoneHaoduanBasedataReqVO", paramType = "body")
	@PostMapping("/create")
	public CreatePhoneHaoduanBasedataResVO createPhoneHaoduanBasedata(@RequestBody CreatePhoneHaoduanBasedataReqVO req) {
		try {
			logger.info("Execute createPhoneHaoduanBasedata, param is {}", req);
			PhoneHaoduanBasedataReqBO reqBO = CommonBeanConvertor.convert(req, PhoneHaoduanBasedataReqBO.class);
			PhoneHaoduanBasedataResBO resBO = phoneHaoduanBasedataService.createPhoneHaoduanBasedata(reqBO);
			CreatePhoneHaoduanBasedataResVO res = CommonBeanConvertor.convert(resBO, CreatePhoneHaoduanBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreatePhoneHaoduanBasedataResVO.class, req, PhoneHaoduanBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改电话号码段", notes="修改电话号码段")
	@ApiImplicitParam(name = "req", value = "修改电话号码段请求对象", required = true, dataType = "ModifyPhoneHaoduanBasedataReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyPhoneHaoduanBasedataResVO modifyPhoneHaoduanBasedata(@RequestBody ModifyPhoneHaoduanBasedataReqVO req) {
		try {
			logger.info("Execute modifyPhoneHaoduanBasedata, param is {}", req);
			PhoneHaoduanBasedataReqBO reqBO = CommonBeanConvertor.convert(req, PhoneHaoduanBasedataReqBO.class);
			PhoneHaoduanBasedataResBO resBO = phoneHaoduanBasedataService.modifyPhoneHaoduanBasedata(reqBO);
			ModifyPhoneHaoduanBasedataResVO res = CommonBeanConvertor.convert(resBO, ModifyPhoneHaoduanBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyPhoneHaoduanBasedataResVO.class, req, PhoneHaoduanBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除电话号码段", notes="删除电话号码段")
	@ApiImplicitParam(name = "req", value = "修改电话号码段请求对象", required = true, dataType = "DeletePhoneHaoduanBasedataReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeletePhoneHaoduanBasedataResVO deletePhoneHaoduanBasedata(@RequestBody DeletePhoneHaoduanBasedataReqVO req) {
		try {
			logger.info("Execute deletePhoneHaoduanBasedata, param is {}", req);
			PhoneHaoduanBasedataReqBO reqBO = CommonBeanConvertor.convert(req, PhoneHaoduanBasedataReqBO.class);
			PhoneHaoduanBasedataResBO resBO = phoneHaoduanBasedataService.deletePhoneHaoduanBasedata(reqBO);
			DeletePhoneHaoduanBasedataResVO res = CommonBeanConvertor.convert(resBO, DeletePhoneHaoduanBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeletePhoneHaoduanBasedataResVO.class, req, PhoneHaoduanBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询电话号码段", notes="查询电话号码段")
	@ApiImplicitParam(name = "req", value = "查询电话号码段请求对象", required = true, dataType = "QueryPhoneHaoduanBasedataReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryPhoneHaoduanBasedataResVO queryPhoneHaoduanBasedata(@RequestBody QueryPhoneHaoduanBasedataReqVO req) {
		try {
			logger.info("Execute queryPhoneHaoduanBasedata, param is {}", req);
			PhoneHaoduanBasedataReqBO reqBO = CommonBeanConvertor.convert(req, PhoneHaoduanBasedataReqBO.class);
			PhoneHaoduanBasedataResBO resBO = phoneHaoduanBasedataService.queryPhoneHaoduanBasedata(reqBO);
			QueryPhoneHaoduanBasedataResVO res = CommonBeanConvertor.convert(resBO, QueryPhoneHaoduanBasedataResVO.class, PhoneHaoduanBasedataBeanVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, QueryPhoneHaoduanBasedataResVO.class, req, PhoneHaoduanBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
}
